package com.google.shop.product.service.impl.member;

import com.google.shop.product.common.utils.JwtUtils;
import com.google.shop.product.common.utils.MD5;
import com.google.shop.product.common.utils.R;
import com.google.shop.product.entity.member.BuyerInfo;
import com.google.shop.product.repository.member.BuyerInfoRepository;
import com.google.shop.product.service.member.BuyerInfoService;
import com.google.shop.product.vo.member.BuyerInfoVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/* loaded from: app.jar:BOOT-INF/classes/com/google/shop/product/service/impl/member/BuyerInfoImpl.class */
public class BuyerInfoImpl implements BuyerInfoService {
    @Autowired
    BuyerInfoRepository buyerInfoRepository;

    @Override // com.google.shop.product.service.member.BuyerInfoService
    public void saveBuyerInfo(BuyerInfoVO buyerInfoVO) {
        buyerInfoVO.setBuyerPassword(MD5.encrypt(buyerInfoVO.getBuyerPassword()));
        BuyerInfo buyerInfo = new BuyerInfo();
        BeanUtils.copyProperties(buyerInfoVO, buyerInfo);
        this.buyerInfoRepository.save(buyerInfo);
    }

    @Override // com.google.shop.product.service.member.BuyerInfoService
    public R login(BuyerInfoVO buyerInfoVO) {
        BuyerInfo buyerInfo = this.buyerInfoRepository.findByBuyerEmail(buyerInfoVO.getBuyerEmail());
        if (buyerInfo == null || !buyerInfo.getBuyerPassword().equals(MD5.encrypt(buyerInfoVO.getBuyerPassword()))) {
            return R.error("账号密码错误");
        }
        String jwtToken = JwtUtils.getJwtToken(buyerInfo.getBuyerId() + "", buyerInfo.getBuyerEmail());
        System.out.println(jwtToken);
        return R.ok(jwtToken);
    }

    @Override // com.google.shop.product.service.member.BuyerInfoService
    public BuyerInfo findByBuyerEmail(String email) {
        return this.buyerInfoRepository.findByBuyerEmail(email);
    }
}
